<?php

namespace mpend\modules\user\models;

use Yii;

/**
 * 签到查询
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class SigninLogSearch extends \common\models\user\UserSigninHistory {

    public $month;

    /**
     * 签到检测
     */
    public function search() {
        $query = static::find()->where([
            'user_id' => $this->user_id,
        ]);
        $start_date = date('Y-m-d', strtotime($this->month));
        $end_date = date('Y-m-d', strtotime("{$this->month} +1 month -1 seconds"));
        $query->andFilterWhere(['between', 'first_date', $start_date, $end_date]);
        return $query->one();
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'user_id',
            'days',
            'sign_days',
            'first_date',
            'last_date',
            'history',
            'sign_dates' => 'signDates',
        ];
    }

}
